home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / SDKs / Apple Game Sprockets / DrawSprocket / GoggleSprocket / Driver Sample Code / SimulEyes / SimulEyes.c next >
Encoding:
C/C++ Source or Header  |  1998-03-12  |  7.5 KB  |  307 lines  |  [TEXT/CWIE]

  1. /*
  2. ********************************************************************************
  3. **
  4. ** File: SimulEyes.c
  5. **
  6. ** Description:
  7. **
  8. **    This is a sample driver for GoggleSprocket, the stereoscopic device
  9. **    interface for the Macintosh.  This driver will drive a pair of
  10. **    SimulEyes LCD glasses from StereoGraphics corporation.
  11. **
  12. ** © 1996 Apple Computer, Inc.  All Rights Reserved.
  13. **
  14. ********************************************************************************
  15. */
  16. #include <Types.h>
  17. #include <Files.h>
  18.  
  19. #include "GoggleSprocketDevices.h"
  20.  
  21. #define kDialogID        128
  22. #define kItemOK            1
  23.  
  24. /*
  25. ********************************************************************************
  26. ** globals
  27. ********************************************************************************
  28. */
  29. /* this device only supports a single "mode" */
  30. GSpDeviceModeInfo gModeInfo = {
  31.     /* mode format is normal */
  32.     kGSpModeDataFormat_Normal,
  33.     
  34.     /* special attributes */
  35.     kGSpModeAttribute_CustomProcess |            /* driver must process the images */
  36.     kGSpModeAttribute_FullDisplayRequired |        /* must be a full screen display     */
  37.     kGSpModeAttribute_PrimeBuffers,                /* images must be preloaded into buffers before processing */
  38.     
  39.     /* display id (none required) */
  40.     0,
  41.     
  42.     /* display requirement ranges */
  43.     { 0, 0 },
  44.     { 0, 0 },
  45.     { 0, 0 },
  46.     { 0, 0 }
  47. };
  48.  
  49. /*
  50. ********************************************************************************
  51. **
  52. ** Name: GSpDevice_Open
  53. **
  54. ** Description:
  55. **
  56. **    Called to allow the driver to do any setup.
  57. **
  58. ********************************************************************************
  59. */
  60. OSStatus                            /* result code                            */
  61. GSpDevice_Open( void )
  62. {
  63.     return noErr;
  64. }
  65.  
  66. /*
  67. ********************************************************************************
  68. **
  69. ** Name: GSpDevice_Close
  70. **
  71. ** Description:
  72. **
  73. **    Called to allow the driver to clean up.
  74. **
  75. ********************************************************************************
  76. */
  77. OSStatus                            /* result code                            */
  78. GSpDevice_Close( void )
  79. {
  80.     return noErr;
  81. }
  82.  
  83. /*
  84. ********************************************************************************
  85. **
  86. ** Name: GSpDevice_Configure
  87. **
  88. ** Description:
  89. **
  90. **    Called to tell the driver to display and manage its configuration dialog.
  91. **
  92. ********************************************************************************
  93. */
  94. OSStatus                            /* result code                            */
  95. GSpDevice_Configure(
  96.     Point *inUpperLeft                /* upper left corner of window, or NULL    */
  97. )
  98. {
  99.     DialogPtr theDialog;
  100.     GrafPtr theSavePort;
  101.     
  102.     GetPort( &theSavePort );
  103.     
  104.     theDialog = GetNewDialog( kDialogID, NULL, (GrafPtr)-1 );
  105.     if( theDialog )
  106.     {    
  107.         short theItem = 0;
  108.         
  109.         SetDialogDefaultItem( theDialog, kItemOK );
  110.         
  111.         // if an upper left is provided, use it (parameter may be NULL)
  112.         if( inUpperLeft )
  113.             MoveWindow( theDialog, inUpperLeft->h, inUpperLeft->v, true );
  114.         ShowWindow( theDialog );
  115.         
  116.         // show the dialog
  117.         while( theItem != kItemOK )
  118.             ModalDialog( nil, &theItem );
  119.             
  120.         // release the dialog memory
  121.         DisposeDialog( theDialog );
  122.     }
  123.     
  124.     SetPort( theSavePort );
  125.     
  126.     return noErr;
  127. }
  128.  
  129. /*
  130. ********************************************************************************
  131. **
  132. ** Name: GSpDevice_GetFirstModeInfo
  133. **
  134. ** Description:
  135. **
  136. **    Return the first available mode the device supports.
  137. **
  138. ********************************************************************************
  139. */
  140. OSStatus                            /* result code                            */
  141. GSpDevice_GetFirstModeInfo(
  142.     GSpDeviceModeInfo *outFirstModeInfo        /* mode information (output)    */
  143. )
  144. {
  145.     *outFirstModeInfo = gModeInfo;
  146.     return noErr;
  147. }
  148.  
  149. /*
  150. ********************************************************************************
  151. **
  152. ** Name: GSpDevice_Open
  153. **
  154. ** Description:
  155. **
  156. **    The driver open call.
  157. **
  158. ********************************************************************************
  159. */
  160. OSStatus                            /* result code                            */
  161. GSpDevice_GetNextModeInfo(
  162.     GSpDeviceModeInfo *inCurrentModeInfo,
  163.     GSpDeviceModeInfo *outNextModeInfo
  164. )
  165. {
  166.     return kGSpDeviceError_NoMoreModes;
  167. }
  168.  
  169. /*
  170. ********************************************************************************
  171. **
  172. ** Name: GSpDevice_SetVisibleEye
  173. **
  174. ** Description:
  175. **
  176. **    Set the eye that can currently see the stereo image.
  177. **
  178. ********************************************************************************
  179. */
  180. OSStatus                            /* result code                            */
  181. GSpDevice_SetVisibleEye(
  182.     Boolean inLeftEyeVisible        /* TRUE = make left eye visible            */
  183. )
  184. {
  185.     return kGSpDeviceError_UnsupportedCall;
  186. }
  187.  
  188. /*
  189. ********************************************************************************
  190. **
  191. ** Name: GSpDevice_GetVisibleEye
  192. **
  193. ** Description:
  194. **
  195. **    The driver open call.
  196. **
  197. ********************************************************************************
  198. */
  199. OSStatus                            /* result code                            */
  200. GSpDevice_GetVisibleEye(
  201.     Boolean *outLeftEyeVisible        /* TRUE = left eye is visible            */
  202. )
  203. {
  204.     return kGSpDeviceError_UnsupportedCall;
  205. }
  206.  
  207. /*
  208. ********************************************************************************
  209. **
  210. ** Name: GSpDevice_CustomBufferProcess
  211. **
  212. ** Description:
  213. **
  214. **    The catch-all call that allows drivers with unique requirements to
  215. **    operate.
  216. **
  217. **    The SimulEyes glasses encode a signal in the last scan line of the
  218. **    image buffer by drawing a blue line followed by a black line.  For
  219. **    the left eye, a blue line 1/4 the width of the buffer is drawn, followed
  220. **    by a 3/4 buffer-width black line.  For the right eye, the blue line
  221. **    is 3/4 buffer-width, and the black line is 1/4 buffer width.  This
  222. **    encoding MUST occur on the last scanline of the display, so simply
  223. **    placing them at the bottom of a window won't work. 
  224. **
  225. ********************************************************************************
  226. */
  227. OSStatus GSpDevice_CustomBufferProcess(
  228.             CGrafPtr inLeftEyeBuffer,        /* left eye image                */
  229.             CGrafPtr inRightEyeBuffer,        /* right eye image                */
  230.             CGrafPtr inDestBuffer,            /* right eye image                */
  231.             Boolean inBuildLeftEyeBuffer,    /* 0 = build right eye image    */
  232.             CTabHandle ioColorTable,        /* src color table to use        */
  233.             Boolean *outShowDisplayBuffer,    /* 0 = driver will show output    */
  234.             Boolean *outCTabChanged )        /* 0 = driver didnt change ctab    */
  235. {
  236.     GrafPtr theSavePort;
  237.     UInt32 theWidth, theHeight;
  238.     
  239.     GetPort( &theSavePort );
  240.     
  241.     /* we're assuming the buffers are the same dimensions here */
  242.     theWidth = inLeftEyeBuffer->portRect.right - inLeftEyeBuffer->portRect.left;
  243.     theHeight = inLeftEyeBuffer->portRect.bottom - 1;
  244.     
  245.     /* encode the appropriate sync information */
  246.     if( inBuildLeftEyeBuffer )
  247.     {    
  248.         SetPort( (GrafPtr)inDestBuffer );
  249.         
  250.         /* blue line */
  251.         ForeColor( blueColor );
  252.         MoveTo( 0, theHeight );
  253.         LineTo( theWidth/4, theHeight );
  254.         
  255.         /* black line */
  256.         ForeColor( blackColor );
  257.         MoveTo( theWidth/4, theHeight );
  258.         LineTo( theWidth, theHeight );
  259.     }
  260.     else
  261.     {
  262.         SetPort( (GrafPtr)inDestBuffer );
  263.         
  264.         /* blue line */
  265.         ForeColor( blueColor );
  266.         MoveTo( 0, theHeight );
  267.         LineTo( theWidth/4 * 3, theHeight );
  268.         
  269.         /* black line */
  270.         ForeColor( blackColor );
  271.         MoveTo( theWidth/4 * 3, theHeight );
  272.         LineTo( theWidth, theHeight );
  273.     }
  274.         
  275.     /* let the caller show the buffer */
  276.     *outShowDisplayBuffer = true;
  277.     
  278.     /* we didn't change the color table */
  279.     *outCTabChanged = false;
  280.     
  281.     /* restore the port */
  282.     SetPort( theSavePort );
  283.     
  284.     return noErr;
  285. }
  286.  
  287. /*
  288. ********************************************************************************
  289. **
  290. ** Name: GSpDevice_GetDeviceKind
  291. **
  292. ** Description:
  293. **
  294. **    Return the kind of device that this is.
  295. **
  296. ********************************************************************************
  297. */
  298. OSStatus                            /* result code                            */
  299. GSpDevice_GetDeviceKind(
  300.     GSpDeviceKind *outDeviceKind
  301. )
  302. {
  303.     *outDeviceKind = kGSpDeviceKind_FrameSequential;
  304.     return noErr;
  305. }
  306.  
  307.